package com.bohua.intermediary.utils;

import com.bohua.intermediary.security.MyUser;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * security工具类
 */
public class SecurityUtils {

    /**
     * 获取登录人主体
     * @return
     */
  public static MyUser getUser(){
      SecurityContext ctx = SecurityContextHolder.getContext();
      Authentication auth = ctx.getAuthentication();
      MyUser user = (MyUser) auth.getPrincipal();
      return user;
  }

}
